package com.google.android.material.bottomappbar;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.ClassLoaderCreator;
import android.os.Parcelable.Creator;
import android.util.AttributeSet;
import android.view.View;
import androidx.annotation.Dimension;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
import androidx.appcompat.widget.ActionMenuView;
import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.widget.Toolbar.LayoutParams;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.coordinatorlayout.widget.CoordinatorLayout.a;
import androidx.coordinatorlayout.widget.CoordinatorLayout.e;
import androidx.core.view.ViewCompat;
import androidx.customview.view.AbsSavedState;
import com.google.android.material.behavior.HideBottomViewOnScrollBehavior;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import o.aqu.c;
import o.aqu.d;
import o.aqu.f;
import o.aqu.n;
import o.aqv;
import o.arc;
import o.asa;
import o.asi;
import o.asq;
import o.ass;
import o.gg;

public class BottomAppBar extends Toolbar implements e {
    @Nullable
    private Animator ʻ;
    private final ass ʼ;
    private final int ʽ;
    private boolean ˊॱ;
    private int ˋॱ;
    private boolean ˏॱ;
    AnimatorListenerAdapter ॱ;
    @Nullable
    private Animator ॱˊ;
    private final arc ॱॱ;
    @Nullable
    private Animator ᐝ;

    public static class Behavior extends HideBottomViewOnScrollBehavior<BottomAppBar> {
        private final Rect ˎ = new Rect();

        public /* synthetic */ boolean ˎ(CoordinatorLayout coordinatorLayout, View view, int i) {
            return ॱ(coordinatorLayout, (BottomAppBar) view, i);
        }

        public Behavior(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
        }

        private boolean ˊ(FloatingActionButton floatingActionButton, BottomAppBar bottomAppBar) {
            ((a) floatingActionButton.getLayoutParams()).ˋ = 17;
            bottomAppBar.ˊ(floatingActionButton);
            return true;
        }

        public boolean ॱ(CoordinatorLayout coordinatorLayout, BottomAppBar bottomAppBar, int i) {
            FloatingActionButton ˋ = bottomAppBar.ˎˎ();
            if (ˋ != null) {
                ˊ(ˋ, bottomAppBar);
                ˋ.ˊ(this.ˎ);
                bottomAppBar.ˊ(this.ˎ.height());
            }
            if (!bottomAppBar.ˎˏ()) {
                bottomAppBar.ˏˏ();
            }
            coordinatorLayout.ˋ(bottomAppBar, i);
            return super.ˎ(coordinatorLayout, bottomAppBar, i);
        }

        public boolean ˏ(@NonNull CoordinatorLayout coordinatorLayout, @NonNull BottomAppBar bottomAppBar, @NonNull View view, @NonNull View view2, int i, int i2) {
            return bottomAppBar.ˋˋ() && super.ˏ(coordinatorLayout, (View) bottomAppBar, view, view2, i, i2);
        }

        protected void ˋ(BottomAppBar bottomAppBar) {
            super.ˋ(bottomAppBar);
            FloatingActionButton ˋ = bottomAppBar.ˎˎ();
            if (ˋ != null) {
                ˋ.clearAnimation();
                ˋ.animate().translationY(bottomAppBar.ˋᐝ()).setInterpolator(aqv.ˎ).setDuration(225);
            }
        }

        protected void ˊ(BottomAppBar bottomAppBar) {
            super.ˊ(bottomAppBar);
            FloatingActionButton ˋ = bottomAppBar.ˎˎ();
            if (ˋ != null) {
                ˋ.ॱ(this.ˎ);
                float measuredHeight = (float) (ˋ.getMeasuredHeight() - this.ˎ.height());
                ˋ.clearAnimation();
                ˋ.animate().translationY(((float) (-ˋ.getPaddingBottom())) + measuredHeight).setInterpolator(aqv.ˏ).setDuration(175);
            }
        }
    }

    @Retention(RetentionPolicy.SOURCE)
    public @interface FabAlignmentMode {
    }

    static class SavedState extends AbsSavedState {
        public static final Creator<SavedState> CREATOR = new ClassLoaderCreator<SavedState>() {
            public /* synthetic */ Object createFromParcel(Parcel parcel) {
                return ˏ(parcel);
            }

            public /* synthetic */ Object createFromParcel(Parcel parcel, ClassLoader classLoader) {
                return ˊ(parcel, classLoader);
            }

            public /* synthetic */ Object[] newArray(int i) {
                return ˎ(i);
            }

            public SavedState ˊ(Parcel parcel, ClassLoader classLoader) {
                return new SavedState(parcel, classLoader);
            }

            public SavedState ˏ(Parcel parcel) {
                return new SavedState(parcel, null);
            }

            public SavedState[] ˎ(int i) {
                return new SavedState[i];
            }
        };
        boolean ˎ;
        int ˏ;

        public SavedState(Parcelable parcelable) {
            super(parcelable);
        }

        public SavedState(Parcel parcel, ClassLoader classLoader) {
            super(parcel, classLoader);
            this.ˏ = parcel.readInt();
            this.ˎ = parcel.readInt() != 0;
        }

        public void writeToParcel(@NonNull Parcel parcel, int i) {
            super.writeToParcel(parcel, i);
            parcel.writeInt(this.ˏ);
            parcel.writeInt(this.ˎ ? 1 : 0);
        }
    }

    public BottomAppBar(Context context) {
        this(context, null, 0);
    }

    public BottomAppBar(Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, d.ˋ);
    }

    public BottomAppBar(Context context, @Nullable AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ˊॱ = true;
        this.ॱ = new AnimatorListenerAdapter(this) {
            final /* synthetic */ BottomAppBar ˋ;

            {
                this.ˋ = r1;
            }

            public void onAnimationStart(Animator animator) {
                this.ˋ.ॱ(this.ˋ.ˊॱ);
                this.ˋ.ˋ(this.ˋ.ˋॱ, this.ˋ.ˊॱ);
            }
        };
        TypedArray ॱ = asa.ॱ(context, attributeSet, n.ʼॱ, i, f.ˊॱ, new int[0]);
        ColorStateList ˊ = asi.ˊ(context, ॱ, n.ˉ);
        float dimensionPixelOffset = (float) ॱ.getDimensionPixelOffset(n.ˈ, 0);
        float dimensionPixelOffset2 = (float) ॱ.getDimensionPixelOffset(n.ˋˊ, 0);
        float dimensionPixelOffset3 = (float) ॱ.getDimensionPixelOffset(n.ˊˋ, 0);
        this.ˋॱ = ॱ.getInt(n.ʽॱ, 0);
        this.ˏॱ = ॱ.getBoolean(n.ˊᐝ, false);
        ॱ.recycle();
        this.ʽ = getResources().getDimensionPixelOffset(c.ॱˋ);
        this.ॱॱ = new arc(dimensionPixelOffset, dimensionPixelOffset2, dimensionPixelOffset3);
        asq o_asq = new asq();
        o_asq.ˊ(this.ॱॱ);
        this.ʼ = new ass(o_asq);
        this.ʼ.ॱ(true);
        this.ʼ.ॱ(Style.FILL);
        gg.ॱ(this.ʼ, ˊ);
        ViewCompat.ˏ(this, this.ʼ);
    }

    public void setFabAlignmentMode(int i) {
        ॱ(i);
        ˋ(i, this.ˊॱ);
        this.ˋॱ = i;
    }

    public void setBackgroundTint(@Nullable ColorStateList colorStateList) {
        gg.ॱ(this.ʼ, colorStateList);
    }

    public float ˉ() {
        return this.ॱॱ.ॱ();
    }

    public void setFabCradleMargin(@Dimension float f) {
        if (f != ˉ()) {
            this.ॱॱ.ˊ(f);
            this.ʼ.invalidateSelf();
        }
    }

    @Dimension
    public float ˊˊ() {
        return this.ॱॱ.ˋ();
    }

    public void setFabCradleRoundedCornerRadius(@Dimension float f) {
        if (f != ˊˊ()) {
            this.ॱॱ.ˎ(f);
            this.ʼ.invalidateSelf();
        }
    }

    @Dimension
    public float ˍ() {
        return this.ॱॱ.ˎ();
    }

    public void setCradleVerticalOffset(@Dimension float f) {
        if (f != ˍ()) {
            this.ॱॱ.ˏ(f);
            this.ʼ.invalidateSelf();
        }
    }

    public boolean ˋˋ() {
        return this.ˏॱ;
    }

    public void setHideOnScroll(boolean z) {
        this.ˏॱ = z;
    }

    void ˊ(@Px int i) {
        if (((float) i) != this.ॱॱ.ˊ()) {
            this.ॱॱ.ॱ((float) i);
            this.ʼ.invalidateSelf();
        }
    }

    private void ॱ(int i) {
        if (this.ˋॱ != i && ViewCompat.ˊᐝ(this)) {
            if (this.ʻ != null) {
                this.ʻ.cancel();
            }
            List arrayList = new ArrayList();
            ˎ(i, arrayList);
            ॱ(i, arrayList);
            Animator animatorSet = new AnimatorSet();
            animatorSet.playTogether(arrayList);
            this.ʻ = animatorSet;
            this.ʻ.addListener(new AnimatorListenerAdapter(this) {
                final /* synthetic */ BottomAppBar ˋ;

                {
                    this.ˋ = r1;
                }

                public void onAnimationEnd(Animator animator) {
                    this.ˋ.ʻ = null;
                }
            });
            this.ʻ.start();
        }
    }

    private void ˎ(int i, List<Animator> list) {
        if (this.ˊॱ) {
            ValueAnimator ofFloat = ValueAnimator.ofFloat(new float[]{this.ॱॱ.ˏ(), (float) ˏ(i)});
            ofFloat.addUpdateListener(new AnimatorUpdateListener(this) {
                final /* synthetic */ BottomAppBar ˎ;

                {
                    this.ˎ = r1;
                }

                public void onAnimationUpdate(ValueAnimator valueAnimator) {
                    this.ˎ.ॱॱ.ˋ(((Float) valueAnimator.getAnimatedValue()).floatValue());
                    this.ˎ.ʼ.invalidateSelf();
                }
            });
            ofFloat.setDuration(300);
            list.add(ofFloat);
        }
    }

    @Nullable
    private FloatingActionButton ˎˎ() {
        if (!(getParent() instanceof CoordinatorLayout)) {
            return null;
        }
        for (View view : ((CoordinatorLayout) getParent()).ॱ((View) this)) {
            if (view instanceof FloatingActionButton) {
                return (FloatingActionButton) view;
            }
        }
        return null;
    }

    private boolean ˌ() {
        FloatingActionButton ˎˎ = ˎˎ();
        return ˎˎ != null && ˎˎ.ʽ();
    }

    private void ॱ(int i, List<Animator> list) {
        ObjectAnimator ofFloat = ObjectAnimator.ofFloat(ˎˎ(), "translationX", new float[]{(float) ˏ(i)});
        ofFloat.setDuration(300);
        list.add(ofFloat);
    }

    private void ˋ(int i, boolean z) {
        int i2 = 0;
        if (ViewCompat.ˊᐝ(this)) {
            if (this.ॱˊ != null) {
                this.ॱˊ.cancel();
            }
            Collection arrayList = new ArrayList();
            if (ˌ()) {
                i2 = i;
            } else {
                z = false;
            }
            ˏ(i2, z, arrayList);
            Animator animatorSet = new AnimatorSet();
            animatorSet.playTogether(arrayList);
            this.ॱˊ = animatorSet;
            this.ॱˊ.addListener(new AnimatorListenerAdapter(this) {
                final /* synthetic */ BottomAppBar ˏ;

                {
                    this.ˏ = r1;
                }

                public void onAnimationEnd(Animator animator) {
                    this.ˏ.ॱˊ = null;
                }
            });
            this.ॱˊ.start();
        }
    }

    private void ˏ(final int i, final boolean z, List<Animator> list) {
        final ActionMenuView ͺॱ = ͺॱ();
        if (ͺॱ != null) {
            ObjectAnimator ofFloat = ObjectAnimator.ofFloat(ͺॱ, "alpha", new float[]{1.0f});
            if ((this.ˊॱ || (z && ˌ())) && (this.ˋॱ == 1 || i == 1)) {
                ObjectAnimator.ofFloat(ͺॱ, "alpha", new float[]{0.0f}).addListener(new AnimatorListenerAdapter(this) {
                    final /* synthetic */ BottomAppBar ˎ;
                    public boolean ॱ;

                    public void onAnimationCancel(Animator animator) {
                        this.ॱ = true;
                    }

                    public void onAnimationEnd(Animator animator) {
                        if (!this.ॱ) {
                            this.ˎ.ॱ(ͺॱ, i, z);
                        }
                    }
                });
                AnimatorSet animatorSet = new AnimatorSet();
                animatorSet.setDuration(150);
                animatorSet.playSequentially(new Animator[]{r2, ofFloat});
                list.add(animatorSet);
            } else if (ͺॱ.getAlpha() < 1.0f) {
                list.add(ofFloat);
            }
        }
    }

    private void ॱ(boolean z) {
        if (ViewCompat.ˊᐝ(this)) {
            if (this.ᐝ != null) {
                this.ᐝ.cancel();
            }
            List arrayList = new ArrayList();
            boolean z2 = z && ˌ();
            ˊ(z2, arrayList);
            ˋ(z, arrayList);
            Animator animatorSet = new AnimatorSet();
            animatorSet.playTogether(arrayList);
            this.ᐝ = animatorSet;
            this.ᐝ.addListener(new AnimatorListenerAdapter(this) {
                final /* synthetic */ BottomAppBar ˎ;

                {
                    this.ˎ = r1;
                }

                public void onAnimationEnd(Animator animator) {
                    this.ˎ.ᐝ = null;
                }
            });
            this.ᐝ.start();
        }
    }

    private void ˊ(boolean z, List<Animator> list) {
        if (z) {
            this.ॱॱ.ˋ(ˑ());
        }
        float[] fArr = new float[2];
        fArr[0] = this.ʼ.ॱ();
        fArr[1] = z ? 1.0f : 0.0f;
        ValueAnimator ofFloat = ValueAnimator.ofFloat(fArr);
        ofFloat.addUpdateListener(new AnimatorUpdateListener(this) {
            final /* synthetic */ BottomAppBar ˊ;

            {
                this.ˊ = r1;
            }

            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                this.ˊ.ʼ.ˋ(((Float) valueAnimator.getAnimatedValue()).floatValue());
            }
        });
        ofFloat.setDuration(300);
        list.add(ofFloat);
    }

    private void ˋ(boolean z, List<Animator> list) {
        FloatingActionButton ˎˎ = ˎˎ();
        if (ˎˎ != null) {
            ObjectAnimator ofFloat = ObjectAnimator.ofFloat(ˎˎ, "translationY", new float[]{ˊ(z)});
            ofFloat.setDuration(300);
            list.add(ofFloat);
        }
    }

    private float ˊ(boolean z) {
        FloatingActionButton ˎˎ = ˎˎ();
        if (ˎˎ == null) {
            return 0.0f;
        }
        Rect rect = new Rect();
        ˎˎ.ॱ(rect);
        float height = (float) rect.height();
        if (height == 0.0f) {
            height = (float) ˎˎ.getMeasuredHeight();
        }
        float height2 = (float) (ˎˎ.getHeight() - rect.bottom);
        height = ((height / 2.0f) + (-ˍ())) + height2;
        height2 = ((float) (ˎˎ.getHeight() - rect.height())) - ((float) ˎˎ.getPaddingBottom());
        float f = (float) (-getMeasuredHeight());
        if (!z) {
            height = height2;
        }
        return height + f;
    }

    private float ˋᐝ() {
        return ˊ(this.ˊॱ);
    }

    private int ˏ(int i) {
        int i2;
        int i3 = 1;
        if (ViewCompat.ʼ(this) == 1) {
            i2 = 1;
        } else {
            i2 = 0;
        }
        if (i != 1) {
            return 0;
        }
        int measuredWidth = (getMeasuredWidth() / 2) - this.ʽ;
        if (i2 != 0) {
            i3 = -1;
        }
        return i3 * measuredWidth;
    }

    private float ˑ() {
        return (float) ˏ(this.ˋॱ);
    }

    @Nullable
    private ActionMenuView ͺॱ() {
        for (int i = 0; i < getChildCount(); i++) {
            View childAt = getChildAt(i);
            if (childAt instanceof ActionMenuView) {
                return (ActionMenuView) childAt;
            }
        }
        return null;
    }

    private void ॱ(ActionMenuView actionMenuView, int i, boolean z) {
        Object obj;
        if (ViewCompat.ʼ(this) == 1) {
            obj = 1;
        } else {
            obj = null;
        }
        int i2 = 0;
        for (int i3 = 0; i3 < getChildCount(); i3++) {
            Object obj2;
            View childAt = getChildAt(i3);
            if ((childAt.getLayoutParams() instanceof LayoutParams) && (((LayoutParams) childAt.getLayoutParams()).ॱ & 8388615) == 8388611) {
                obj2 = 1;
            } else {
                obj2 = null;
            }
            if (obj2 != null) {
                i2 = Math.max(i2, obj != null ? childAt.getLeft() : childAt.getRight());
            }
        }
        float right = (i == 1 && z) ? (float) (i2 - (obj != null ? actionMenuView.getRight() : actionMenuView.getLeft())) : 0.0f;
        actionMenuView.setTranslationX(right);
    }

    private void ˏˎ() {
        if (this.ᐝ != null) {
            this.ᐝ.cancel();
        }
        if (this.ॱˊ != null) {
            this.ॱˊ.cancel();
        }
        if (this.ʻ != null) {
            this.ʻ.cancel();
        }
    }

    private boolean ˎˏ() {
        return (this.ᐝ != null && this.ᐝ.isRunning()) || ((this.ॱˊ != null && this.ॱˊ.isRunning()) || (this.ʻ != null && this.ʻ.isRunning()));
    }

    public void onLayout(boolean z, int i, int i2, int i3, int i4) {
        super.onLayout(z, i, i2, i3, i4);
        ˏˎ();
        ˏˏ();
    }

    private void ˏˏ() {
        this.ॱॱ.ˋ(ˑ());
        FloatingActionButton ˎˎ = ˎˎ();
        ass o_ass = this.ʼ;
        float f = (this.ˊॱ && ˌ()) ? 1.0f : 0.0f;
        o_ass.ˋ(f);
        if (ˎˎ != null) {
            ˎˎ.setTranslationY(ˋᐝ());
            ˎˎ.setTranslationX(ˑ());
        }
        ActionMenuView ͺॱ = ͺॱ();
        if (ͺॱ != null) {
            ͺॱ.setAlpha(1.0f);
            if (ˌ()) {
                ॱ(ͺॱ, this.ˋॱ, this.ˊॱ);
            } else {
                ॱ(ͺॱ, 0, false);
            }
        }
    }

    private void ˊ(@NonNull FloatingActionButton floatingActionButton) {
        ˋ(floatingActionButton);
        floatingActionButton.ˎ(this.ॱ);
        floatingActionButton.ˋ(this.ॱ);
    }

    private void ˋ(@NonNull FloatingActionButton floatingActionButton) {
        floatingActionButton.ॱ(this.ॱ);
        floatingActionButton.ˏ(this.ॱ);
    }

    public void setTitle(CharSequence charSequence) {
    }

    public void setSubtitle(CharSequence charSequence) {
    }

    @NonNull
    public androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior<BottomAppBar> j_() {
        return new Behavior();
    }

    public Parcelable onSaveInstanceState() {
        Parcelable savedState = new SavedState(super.onSaveInstanceState());
        savedState.ˏ = this.ˋॱ;
        savedState.ˎ = this.ˊॱ;
        return savedState;
    }

    public void onRestoreInstanceState(Parcelable parcelable) {
        if (parcelable instanceof SavedState) {
            SavedState savedState = (SavedState) parcelable;
            super.onRestoreInstanceState(savedState.ˊ());
            this.ˋॱ = savedState.ˏ;
            this.ˊॱ = savedState.ˎ;
            return;
        }
        super.onRestoreInstanceState(parcelable);
    }
}
